﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace NhWeather.Register;

public class SensorRegister : InputRegister
{
    public SensorRegister(short max, short min) :base()
    {
        MaxValue = max;
        MinValue = min;
        Random rd = new();
        Data = (short)rd.Next(min, max);
        int iMax = (int)(max * 0.01);
        int iMin = (int)(min * 0.01);
        ChangeAmplitude = rd.Next(iMin, iMax);
    }

    /// <summary>
    /// 生成随机变动的数据
    /// </summary>
    public override void Generate()
    {
        Random rd = new();
        int temp = Data + rd.Next(-6, 6) * ChangeAmplitude;

        if (MinValue != null && temp < MinValue)
        {
            temp = (int)MinValue;
        }
        else if (MaxValue != null && temp > MaxValue)
        {
            temp = (int)MaxValue;
        }
        Data = (short)temp;
    }
}
